package com.woniu.service.impl;

import com.woniu.dao.AliPayDao;
import com.woniu.entity.Course;
import com.woniu.entity.Order;
import com.woniu.service.AliPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.relational.core.sql.In;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class AliPayServiceImpl implements AliPayService {

    @Autowired
    private AliPayDao aliPayDao;
    /**
     * 阿里生成订单,订单表
     */
    @Override
    public void saveOrder(Order order) {
        aliPayDao.insertOrder(order);
    }

    /**
     * 中间表插入数据
     */
    @Override
    public void saveOrderCourse(String orderId,Integer courseId) {
        int i=aliPayDao.insertOrderCourse(orderId,courseId);
    }

    /**
     * 获取用户余额
     * @param userId
     * @return
     */
    @Override
    public BigDecimal getUserBalance(Integer userId) {
        return aliPayDao.getUserBalance(userId);
    }

    /**
     * 开始扣款
     * @param userId
     * @param nowBalance
     */
    @Override
    public void killBalance(Integer userId, BigDecimal nowBalance) {
        aliPayDao.killBalance(userId,nowBalance);
    }

    /**
     * 向课程和用户中间表插入数据
     * @param userid
     * @param courseId
     */
    @Override
    public void insertIntoUserCourse(Integer userid, Integer courseId) {
        aliPayDao.insertIntoUserCourse(userid,courseId);
    }
}
